package com.zml.control;

import com.alibaba.fastjson.JSON;
import com.huawei.ailifeability.netconfig.api.NetConfigApi;
import com.huawei.ailifeability.netconfig.model.CommonInfo;

import com.zml.control.database.PreferenceDataBase;
import com.zml.control.entity.OcMqttEntity;
import com.zml.control.okhttp.HttpUtils;
import com.zml.control.okhttp.HuaweiCloudApi;
import com.zzrv5.mylibrary.ZZRCallBack;
import com.zzrv5.mylibrary.ZZRHttp;
import ohos.app.Context;
import ohos.data.DatabaseHelper;
import ohos.data.preferences.Preferences;
import ohos.eventhandler.EventHandler;  //线程间通信
import ohos.eventhandler.EventRunner;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;
import ohos.utils.zson.ZSONObject;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * NetworkDeviceDataHandler is used to control Harmony devices. An example of a fan is provided as a reference.
 * Implement two methods, recoverData is used to initialize data, modifyProperty is used to respond to interface
 * operations. {@link NetworkDeviceDataHandler#sendMessage} is used to send messages to the device, After
 * sending successfully, {@link NetworkDeviceDataHandler#onDeviceDataChange(Map)} is called to refresh the UI interface
 */
public class NetworkDeviceDataHandler extends BaseDeviceDataHandler {
    private static final HiLogLabel TAG = new HiLogLabel(HiLog.DEBUG, 0, "MessageDataHandler");
    private static String sessionId = null;
    private final DeviceDataModel dataModel;
    private final EventHandler mainHandler;
    private final Map<String, Object> dataMap = new HashMap<>();
    private final DeviceDataModel solarDataModel = new DeviceDataModel() {
        @Override
        public Map<String, Object> recoverData() {
//            dataMap.put("switch/on", 0);
//            dataMap.put("windMode/mode", 0);
//            dataMap.put("windGear/gear", 0);
//            dataMap.put("shutdown/mode", 0);
//            dataMap.put("infoDisplay/battery", 60);    //add
//            dataMap.put("bluetoothConnectStatus/bluetoothConnectStatus", 1);    //add
            return dataMap;
        }

        @Override
        public Map<String, Object> modifyProperty(String key, Object value) {
            HashMap<String, Object> tmpMap = new HashMap<>();
            tmpMap.put(key, value);
            switch (key) {
                case "switch/on":
                    if ((Integer) value == 0) {
                        sendMessage("010000", tmpMap);
                        tmpMap.put("shutdown/mode", 0);
                    } else {
                        sendMessage("010100", tmpMap);
                    }
                    break;
                case "windMode/mode":
                    if ((Integer) value == 2) {
                        sendMessage("030300", tmpMap);
                    } else {
                        sendMessage("030100", tmpMap);
                    }
                    break;
                case "windGear/gear":
                    if ((Integer) value == 2) {
                        sendMessage("020100", tmpMap);
                    } else if ((Integer) value == 3) {
                        sendMessage("020200", tmpMap);
                    } else if ((Integer) value == 4) {
                        sendMessage("020300", tmpMap);
                    } else {
                        sendMessage("020400", tmpMap);
                    }
                    break;
                case "shutdown/mode":
                    if (value.toString().contains("shutdownTime")) {
                        ZSONObject zsonObject = ZSONObject.stringToZSON(value.toString());
                        int shutdownTime = zsonObject.getInteger("shutdownTime");
                        int shutdownMode = zsonObject.getInteger("shutdown/mode");
                        tmpMap.put("shutdown/mode", shutdownMode);
                        sendMessage("050" + shutdownTime + "00", tmpMap);
                    } else {
                        tmpMap.put("shutdown/mode", 0);
                        sendMessage("050000", tmpMap);
                    }
                    break;
                default:
                    break;
            }
            return dataMap;
        }
    };
    private Context context;

    NetworkDeviceDataHandler(String deviceId, DeviceDataCallback deviceDataCallback) {
        super(deviceId, deviceDataCallback);
        dataModel = solarDataModel;
        mainHandler = new EventHandler(EventRunner.getMainEventRunner());
        mainHandler.postTask(() -> initProfileData(0, "", dataModel.recoverData()));
    }

    public static String getSessionId() {
        return sessionId;
    }

    public static void setSessionId(String id) {
        sessionId = id;
    }

    private void sendMessage(String message, HashMap<String, Object> tmpMap) {
        CommonInfo commonInfo = new CommonInfo();
        commonInfo.setSessionId(sessionId);
        HiLog.error(TAG, "sessionId " + sessionId);
        NetConfigApi.getInstance().sendMessage(commonInfo, message, (code, controlMessage, str) -> {
            if (code == 0) {
                HiLog.info(TAG, "send message success " + message);
                dataMap.putAll(tmpMap);
                mainHandler.postTask(() -> onDeviceDataChange(dataMap));
            } else {
                HiLog.error(TAG, "send message fail code = " +
                        code + " control message = " + controlMessage);
            }
        });
    }

    @Override
    public void modifyDeviceProperty(String key, Object value) {
        dataModel.modifyProperty(key, value);
    }

    @Override
    void getData() {
        dataMap.put("infoDisplay/battery", 23);    //add
        dataMap.put("bluetoothConnectStatus/bluetoothConnectStatus", 1);    //add

        try {
//            String response = new HttpUtils().getIAMUserToken("https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/0c2785b9a98010d52f9dc00c70d11445/devices/62687d6cb9f9fa4a4f9e3f17_OHOS_MPPT002/shadow");
            ControlMainAbility controlMainAbility = new ControlMainAbility();
            String response = HuaweiCloudApi.showDeviceShadow(controlMainAbility.getContext());
            HiLog.info(TAG, "HilogDebug"+"API返回成功，结果："+response);

            //1.调用fastjson解析，结果保存在JSON对应的类
            OcMqttEntity ocmqttentity = JSON.parseObject(response,OcMqttEntity.class);

            //这部分用来更新UI
            ZSONObject zsonObject = new ZSONObject(); //首先，将要刷新的数据存放在一个ZSONObject实例中
            //失败返回{"error_msg":"Incorrect IAM authentication information: x-auth-token not found","error_code":"APIG.0301","request_id":"483907208e6ce86b662ee9571d65f113"}
            if(ocmqttentity.getDevice_id() != null){
                float InVoltage = ocmqttentity.getShadow().get(0).getReported().getProperties().getInVoltage();
                float OutVoltage = ocmqttentity.getShadow().get(0).getReported().getProperties().getOutVoltage();
                float InCurrent = ocmqttentity.getShadow().get(0).getReported().getProperties().getInCurrent();
                float OutCurrent = ocmqttentity.getShadow().get(0).getReported().getProperties().getOutCurrent();
                float InPower = OutVoltage*InCurrent;
                float efficiency = 98.2f;

//                            zsonObject.put("service_id",ocmqttentity.getDevice_id());
                zsonObject.put("InVoltage",InVoltage);
                zsonObject.put("OutVoltage",OutVoltage);
                zsonObject.put("InCurrent",InCurrent);
                zsonObject.put("OutCurrent",OutCurrent);
                zsonObject.put("InPower",InPower);
                zsonObject.put("efficiency",efficiency);

            }else {
                HiLog.info(TAG, "HilogDebug"+"NetworkDeviceDataHandler：result");
                HiLog.info(TAG, "result.toString(): ");  // test
            }
            for (Map.Entry<String, Object> entry : zsonObject.entrySet()) {
                dataMap.put(entry.getKey(), entry.getValue());
                HiLog.info(TAG, "HilogDebug"+"NetworkDeviceDataHandler：entry.getKey()"+entry.getKey());
                HiLog.info(TAG, "HilogDebug"+"NetworkDeviceDataHandler：entry.getValue()"+entry.getValue().toString());
            }


        }catch (Exception e){
            e.printStackTrace();
            HiLog.info(TAG, "HilogDebug"+"API返回失败");
        }

//        // 获取华为云IotDA设备影子数据
//        String url = "https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/0c2785b9a98010d52f9dc00c70d11445/devices/62687d6cb9f9fa4a4f9e3f17_OHOS_MPPT002/shadow"; //TODO：
//        Map<String, String> paramsMap = new HashMap<String,String>();       //数据采用的哈希表结构
//        Map<String, String> headerMap = new HashMap<String,String>();       //数据采用的哈希表结构
//        // [{"key":"Content-Type","value":"application/json","description":"","type":"text","enabled":true}]
//        headerMap.put("Content-Type", "application/json");//给map中添加元素
//        headerMap.put("X-Auth-Token", "MIITqwYJKoZIhvcNAQcCoIITnDCCE5gCAQExDTALBglghkgBZQMEAgEwghG9BgkqhkiG9w0BBwGgghGuBIIRqnsidG9rZW4iOnsiZXhwaXJlc19hdCI6IjIwMjItMTAtMDdUMTI6NTk6MjguNzE1MDAwWiIsIm1ldGhvZHMiOlsicGFzc3dvcmQiXSwiY2F0YWxvZyI6W10sInJvbGVzIjpbeyJuYW1lIjoidGVfYWRtaW4iLCJpZCI6IjAifSx7Im5hbWUiOiJ0ZV9hZ2VuY3kiLCJpZCI6IjAifSx7Im5hbWUiOiJvcF9nYXRlZF9lY3Nfc3BvdF9pbnN0YW5jZSIsImlkIjoiMCJ9LHsibmFtZSI6Im9wX2dhdGVkX2l2YXNfdmNyX3ZjYSIsImlkIjoiMCJ9LHsibmFtZSI6Im9wX2dhdGVkX2FfY24tc291dGgtNGMiLCJpZCI6IjAifSx7Im5hbWUiOiJvcF9nYXRlZF9lY3Nfa2FlMSIsImlkIjoiMCJ9LHsibmFtZSI6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DAifSwibmFtZSI6ImNuLW5vcnRoLTQiLCJpZCI6IjBjMjc4NWI5YTk4MDEwZDUyZjlkYzAwYzcwZDExNDQ1In0sImlzc3VlZF9hdCI6IjIwMjItMTAtMDZUMTI6NTk6MjguNzE1MDAwWiIsInVzZXIiOnsiZG9tYWluIjp7Im5hbWUiOiJCcmlnaHRfTUwiLCJpZCI6IjBhODcwMThiNjYwMGYyMjcwZjRjYzAwY2M5MzY2OTQwIn0sIm5hbWUiOiJCcmlnaHRfTUwiLCJwYXNzd29yZF9leHBpcmVzX2F0IjoiIiwiaWQiOiIwYTg3MDE4YzU0ODBmMjJjMWYxNmMwMGM5OTY5NDczMyJ9fX0xggHBMIIBvQIBATCBlzCBiTELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUd1YW5nRG9uZzERMA8GA1UEBwwIU2hlblpoZW4xLjAsBgNVBAoMJUh1YXdlaSBTb2Z0d2FyZSBUZWNobm9sb2dpZXMgQ28uLCBMdGQxDjAMBgNVBAsMBUNsb3VkMRMwEQYDVQQDDApjYS5pYW0ucGtpAgkA3LMrXRBhahAwCwYJYIZIAWUDBAIBMA0GCSqGSIb3DQEBAQUABIIBADEjz6Nzx1yqAJc5J8cIwN");//给map中添加元素
//
////            Map<String, Object> dataMap = new HashMap<>();  // 将get到的数据保存在dataMap
//        // 发起get请求
//        ZZRHttp.post(url,paramsMap,headerMap,new ZZRCallBack.CallBackString() {
//            @Override
//            public void onFailure(int i, String s) {
//                HiLog.info(TAG, "HilogDebug"+"API返回失败，结果："+s);
//                HiLog.info(TAG, "API返回失败，结果："+s);
//            }
//            @Override
//            public void onResponse(String s) {
//                HiLog.info(TAG, "HilogDebug"+"API返回成功，结果："+s);
//                HiLog.info(TAG, "API返回成功，结果："+s);
//                try {
//                    //1.调用fastjson解析，结果保存在JSON对应的类
//                    OcMqttEntity ocmqttentity = JSON.parseObject(s,OcMqttEntity.class);
//
//                    //这部分用来更新UI
//                    ZSONObject zsonObject = new ZSONObject(); //首先，将要刷新的数据存放在一个ZSONObject实例中
//                    //失败返回{"error_msg":"Incorrect IAM authentication information: x-auth-token not found","error_code":"APIG.0301","request_id":"483907208e6ce86b662ee9571d65f113"}
//                    if(ocmqttentity.getDevice_id() != null){
//                        float InVoltage = ocmqttentity.getShadow().get(0).getReported().getProperties().getInVoltage();
//                        float OutVoltage = ocmqttentity.getShadow().get(0).getReported().getProperties().getOutVoltage();
//                        float InCurrent = ocmqttentity.getShadow().get(0).getReported().getProperties().getInCurrent();
//                        float InPower = OutVoltage*InCurrent;
//                        float efficiency = 98.2f;
//
////                            zsonObject.put("service_id",ocmqttentity.getDevice_id());
//                        zsonObject.put("InVoltage",InVoltage);
//                        zsonObject.put("OutVoltage",OutVoltage);
//                        zsonObject.put("InCurrent",InCurrent);
//                        zsonObject.put("InPower",InPower);
//                        zsonObject.put("efficiency",efficiency);
//
//                    }else {
//                        HiLog.info(TAG, "HilogDebug"+"NetworkDeviceDataHandler：result");
//                        HiLog.info(TAG, "result.toString(): ");  // test
//                    }
//                    for (Map.Entry<String, Object> entry : zsonObject.entrySet()) {
//                        dataMap.put(entry.getKey(), entry.getValue());
//                        HiLog.info(TAG, "HilogDebug"+"NetworkDeviceDataHandler：entry.getKey()"+entry.getKey());
//                        HiLog.info(TAG, "HilogDebug"+"NetworkDeviceDataHandler：entry.getValue()"+entry.getValue().toString());
//                    }
//                } catch (Exception e) {
//                    HiLog.info(TAG, "HilogDebug"+"解析失败"+ e.getMessage());
//                    HiLog.info(TAG, "解析失败"+ e.getMessage());
//                }
//                // 更新UI
////                mainHandler.postTask(() -> initProfileData(0, "", dataMap));
//            }
//        });

        onDeviceDataChange(dataMap);
//        onDeviceDataChange(HuaweiCloudApi.showDeviceShadow());
    }

    private interface DeviceDataModel {
        Map<String, Object> recoverData();

        Map<String, Object> modifyProperty(String key, Object value);
    }
}
